home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoPageAllocation.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.9 KB  |  221 lines

  1. /*
  2.  *   $RCSfile: undoPageAllocation.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "openlog.h"
  60. #include "logrecs.h"
  61. #include "trans.h"
  62. #include "bitmap.h"
  63. #include "undo.h"
  64. #include "io_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "bm_extfuncs.h"
  67. #include "log_extfuncs.h"
  68. #include "undo_extfuncs.h"
  69. #include "logaction.h"
  70. #include "util_funcs.h"
  71. #include "thread_globals.h"
  72.  
  73.  
  74.  void
  75. undoPageAllocation (
  76.  
  77.     LOGRECORDHDR        *recordHeader 
  78. )
  79. {
  80.  
  81.     register VOLREC        *volRec;
  82.     register PID        *pidList;
  83.     LIST                bitmapList;
  84.     LOGRECORDINFO        recordInfo;
  85.     FORCEMARK            forceMark;
  86.     LSN                    lsn;
  87.     LRC                 *lrcList;
  88.     LRC                 lrcShortList[LRC_SHORTLIST_SIZE];
  89.     int                 lrcCount;
  90.     LRC                 *headerLRC; /* LRC on volume header */
  91.     PAGEALLOCINFO       pageAllocInfo;
  92.     int                    i;
  93.  
  94.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
  95.  
  96.     /*
  97.      *    get a pointer to the common page allocation info
  98.      *    copy it to a separate area so that is can be updated
  99.      */
  100.     pageAllocInfo = *(PAGEALLOCINFO *) GET_LOG_IMAGE(recordHeader, 0);
  101.     TRPRINT(TR_IO, TR_LEVEL_2, ("numPages:%d", pageAllocInfo.numPages));
  102.  
  103.     /*
  104.      *    get a pointer to the page list in the record
  105.      */
  106.     pidList = (PID *) GET_LOG_IMAGE(recordHeader, 1);
  107.     TRPRINT(TR_IO, TR_LEVEL_2, ("pid:%d", pidList->page));
  108.  
  109.     if ((volRec = io_FindVolRec(pidList->volid)) == NULL)    {
  110.  
  111.         SM_ERROR(TYPE_FATAL, Active->errno);
  112.     }
  113.  
  114.     /*
  115.      *    intialize the bitmap list
  116.      */
  117.     initializeList( &(bitmapList) );
  118.  
  119.     /*
  120.      *    deallocate the page
  121.      */
  122.     if (io_DeallocPages(pageAllocInfo.page2size, 
  123.         (int) pageAllocInfo.numPages, pidList, &bitmapList, FALSE, TRUE))    {
  124.  
  125.         SM_ERROR(TYPE_FATAL, Active->errno);
  126.     }
  127.  
  128.     /*
  129.      *    Remove pages from buffer
  130.      */
  131.     for (i = 0; i < pageAllocInfo.numPages; i++) {
  132.         bf_InvalidatePage(pidList+i);
  133.     }
  134.  
  135.     /*
  136.      *  increment the lrc on each bitmap page, and count the
  137.      *  number of bitmap pages
  138.      */
  139.     bm_ListIncrementCount(&bitmapList, &lrcCount);
  140.  
  141.     /*
  142.      *  Create the lrcList.  If its short, use the one on the stack,
  143.      *  otherwise malloc space and remember to free it before returning.
  144.      *  This is necessary, because the list could potentially be very
  145.      *  large, but usually it will be small.
  146.      */
  147.     if (lrcCount <= LRC_SHORTLIST_SIZE) {
  148.         lrcList = lrcShortList;
  149.     } else {
  150.         lrcList = (LRC*) malloc(lrcCount * sizeof(LRC));
  151.         if (lrcList == NULL) {
  152.             SM_ERROR(TYPE_FATAL, esmMALLOCFAILED);
  153.         }
  154.     }
  155.  
  156.     /*
  157.      *  Store the lrc for each bitmap page in the lrc list
  158.      */
  159.     bm_ListSaveLrc(&bitmapList, lrcList);
  160.  
  161.     /*
  162.      *  Increment the lrc on the volume header
  163.      */
  164.     headerLRC = &(volRec->header->lrc);
  165.     INCREMENT_LRC(headerLRC);
  166.     pageAllocInfo.headerLRC = *headerLRC;
  167.  
  168.     /*
  169.      *    initialize the log information
  170.      */
  171.     recordInfo.type            = LOG_REC_TYPE_COMPENSATION;
  172.     recordInfo.action        = LOG_ACTION_DEALLOCATE_PAGE;
  173.     recordInfo.flags        = NOFLAGS;
  174.     recordInfo.imageCount    = 3;
  175.     recordInfo.actionPid    = NULL;
  176.     recordInfo.imageSize[0] = sizeof(PAGEALLOCINFO);
  177.     recordInfo.imageData[0] = (VOID *) &pageAllocInfo;
  178.     recordInfo.imageSize[1] = (unsigned short) 
  179.         sizeof(PID) * (pageAllocInfo.numPages);
  180.     recordInfo.imageData[1] = (VOID *) pidList;
  181.     recordInfo.imageSize[2] = sizeof(LRC) * lrcCount;
  182.     recordInfo.imageData[2] = (VOID *) lrcList;
  183.     recordInfo.flags        = NOFLAGS;
  184.     recordInfo.nextUndoLSN    = recordHeader->previousLSN;
  185.  
  186.     /*
  187.      *    write the record to the log
  188.      */
  189.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  190.                               &lsn, NOFLAGS)) < 0)    {
  191.  
  192.         /*
  193.          *  free any malloced list space and return failure
  194.          */
  195.         if (lrcList != lrcShortList) free((char*)lrcList);
  196.         SM_ERROR(TYPE_FATAL, Active->errno);
  197.     }
  198.  
  199.     /*
  200.      *    release the bitmap pages and mark them
  201.      */
  202.     bm_ListUnfixDepend( &bitmapList, forceMark, &lsn, lrcList );
  203.  
  204.     /*
  205.      *  free any malloced list space 
  206.      */
  207.     if (lrcList != lrcShortList) free((char*)lrcList);
  208.  
  209.     /*
  210.      *  Mark the volume header dependency
  211.      */
  212.     DEPEND_LOG(volRec->headerLink->pageHash, forceMark, &lsn, headerLRC);
  213.  
  214.     /*
  215.      *    Make sure volume is ok
  216.      */
  217. #ifdef DEBUG
  218.     SM_ASSERT(LEVEL_3, !io_Checker(volRec));
  219. #endif
  220. }
  221.